//按键控制数码管数字显示：按下按键1数字加一；按下按键2数字减一
#include <reg52.h>
#include <intrins.h>
sbit Key1 = P3^1;   //定义按键
sbit Key2 = P3^0;
sbit LSA= P2^2;     
sbit LSB= P2^3;
sbit LSC= P2^4;
unsigned char code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
					0x7f,0x6f,0x77};//数字0~9

void Delay(xms)		//@11.0592MHz  延时函数
{
	unsigned char i, j;
  while(xms--)
	{
	_nop_();
	i = 2;
	j = 199;
	do
	{
		while (--j);
	} while (--i);
}
}


void main()
{
  char i=0;
	LSA=1;			//
	LSA=1;			//选择8号数码管
	LSA=1;			//
	while(1)
	{
		P0=smgduan[i];
		
		if(Key1==0)
		{
			Delay(100);
			if(Key1==0)i++;
			if(i==10)i=9;
			while(!Key1);
		}
		
		if(Key2==0)
		{
			Delay(100);
			if(Key2==0)i--;
			if(i==-1)i=0;
			while(!Key2);
			
			
		}
	}
	
}